<?php

require_once($INCLUDE_PATH.'app/controller/InitController.php');
require_once ($INCLUDE_PATH . "/inc/checkfun.php");
require_once ($INCLUDE_PATH . "/include/checklogin.php");
require_once ($INCLUDE_PATH . "/include/WebService2Db.php");
function __autoload($class_name) {
    require_once APP_ROOT.'app/model/'.strtolower($class_name) . '.php';
}
class SubController extends InitController {

    public function __construct() {
        parent::__construct();

    }

    public function actionList()
    {
        if($_REQUEST['p']) {
            $page = $_REQUEST['p'];
        }else {
            $page = 1;
        }
        $pageSize = 20;
        $sum = SubModel::getListCount();
        if (ceil ( $sum / $pageSize ) <= $page && ceil ( $sum / $pageSize ) != 0) {
            $page = ceil ( $sum / $pageSize );
        }
        $liststart=$pageSize * ($page - 1);
        $result = SubModel::getList($page,$liststart,$pageSize);
        Y::$tpl->set("list",$result);
    }
     
    public function actionSave() {
        if ($_REQUEST['email']) {
            $result = checkLogin::checkSub($_REQUEST['email']);
            if ($result == 1) {
                Header("Location: http://www.baidu.com");
            }else {
                Header("Location: http://www.google.com");
            }
        }
    }

    public function checkSub($email) {
        $exp = "^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
        if(eregi($exp,$email)) { //先用正则表达式验证email格式的有效性

            return true;


        }else {

            return false;

        }

    }


    //echo PRE.'hhj';






}

?>
